import {
    getField
} from '@/api/user'
import {
    Message
} from 'element-ui'
const state = {
    
}
const mutations = {
    
}
const actions = {
    getDict({
        commit
    }, dict) {
        return new Promise((resolve, reject) => {
            getField({
                code: dict.code,
                page: 1,
                size: 1000
            }).then((res) => {
                if (res.status) {
                    const data = res.data.records;
                    let dic = [];
                    data.map(item => {
                        let obj = {};
                        obj = {
                            label: item.fieldName,
                            value: item.fieldCode
                        };
                        dic.push(obj);
                    });
                    resolve(dic);
                } else {
                    Message({
                        message: res.msg,
                        type: 'error'
                    })
                }

            }).catch(err => {
                reject(err);
            })
        })
    },
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}
